package com.evon.yardmanagement.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.evon.yardmanagement.model.Yard;

/**
 * A data access object (DAO) providing persistence and search support for Yard
 * entities. Transaction control of the save(), update() and delete() operations
 * can directly support Spring container-managed transactions or they can be
 * augmented to handle user-managed Spring transactions. Each of these methods
 * provides additional information for how to configure it for the desired type
 * of transaction control.
 * 
 * @see com.abc.yardmanagement.dao.Yard
 * @author MyEclipse Persistence Tools
 */

public class YardDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(YardDAO.class);
	// property constants
	public static final String YARD_NAME = "yardName";
	public static final String ADDRESS = "address";
	public static final String CITY = "city";
	public static final String PHONE = "phone";
	public static final String DESCRIPTION = "description";
	public static final String ACTIVE = "active";
	public static final String HSC_ID = "hscId";
	public static final String HSU_ID = "hsuId";

	@Override
	public Class getQueryClass() {
		// TODO Auto-generated method stub
		return Yard.class;
	}

	public static void main(String args[]) {
		YardDAO yardDAO = new YardDAO();
		System.out.println(yardDAO.findByOemId(1).size());
	}

	public List findByOemId(java.lang.Integer id) {
		log.debug("finding all Oem instances");
		try {

			Criteria criteria = getSession().createCriteria(Yard.class)
					.createAlias("yardMapping", "yardMapping").createAlias("yardMapping.oem", "oem");
			criteria.add(Restrictions.eq("oem.id", id));
			// TODO : add check for yard type
			return criteria.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public List findByYardName(Object yardName) {
		return findByProperty(YARD_NAME, yardName);
	}

	public List findByAddress(Object address) {
		return findByProperty(ADDRESS, address);
	}

	public List findByCity(Object city) {
		return findByProperty(CITY, city);
	}

	public List findByPhone(Object phone) {
		return findByProperty(PHONE, phone);
	}

	public List findByDescription(Object description) {
		return findByProperty(DESCRIPTION, description);
	}

	public List findByActive(Object active) {
		return findByProperty(ACTIVE, active);
	}

	public List findByHscId(Object hscId) {
		return findByProperty(HSC_ID, hscId);
	}

	public List findByHsuId(Object hsuId) {
		return findByProperty(HSU_ID, hsuId);
	}

}